const express = require('express');
const app = express();

// 引入 body-parser
const bodyParser = require('body-parser');
// 引入cors
const cors = require('cors')
// 引入路由对象
const userRouter = require('./routes/userRouter');
const articleRouter = require('./routes/articleRouter');
const treeTableRouter = require('./routes/treeTableRouter');
// 注册
app.use(bodyParser.urlencoded({ extended: true }))
app.use(cors())  // 服务端解决跨域方法
// 添加这一行来解析 JSON 请求体
app.use(express.json());
// 注册路由
app.use('/api', userRouter)
app.use('/article', articleRouter)
app.use('/tree', treeTableRouter)

// http://localhost:8080
app.listen(8080, () => {
  console.log('server is running at port 8080')
})